<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>文章分类-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/resource/backend/css/font.css">
    <link rel="stylesheet" href="/resource/backend/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="weadmin-nav">
			<span class="layui-breadcrumb">
		        <a href="">首页</a>
		        <a href="">栏目管理</a>
		        <a><cite>栏目分类</cite></a>
		    </span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe669;</i></a>
</div>
<div class="weadmin-body">
    <div class="weadmin-block">
        <button class="layui-btn layui-btn-primary" id="expand">全部展开</button>
        <button class="layui-btn layui-btn-primary" id="collapse">全部收起</button>
        <button class="layui-btn" onclick="WeAdminShow('添加分类','${ backend_url `/channel/add` }$')"><i
                class="layui-icon"></i>添加
        </button>
    </div>

    <div id="demo"></div>
</div>
<script src="/resource/backend/lib/layui/layui.js" charset="utf-8"></script>
</body>
<script>
    /*分类-停用*/
    function member_stop(obj, id) {
        var confirmTip;
        var $ = layui.jquery;
        if ($(obj).attr('title') === '启用') {
            confirmTip = '确认要停用吗？';
        } else {
            confirmTip = '确认要启用吗？';
        }
        layer.confirm(confirmTip, function (index) {
            if ($(obj).attr('title') === '启用') {
                //发异步把用户状态进行更改
                $.post('${backend_api_url `/channel/status`}$', {'id': id}, function (res) {
                    if (res.code === 0) {
                        $(obj).attr('title', '停用')
                        $(obj).find('i').html('&#xe62f;');
                        $(obj).parents("tr").find(".td-status").find('span').addClass('layui-bg-gray').removeClass('layui-bg-blue').html('已停用');
                        layer.msg('已停用!', {
                            icon: 6,
                            time: 1000
                        });
                    } else {
                        //操作失败
                        layer.msg(res.message, {
                            icon: 5,
                            time: 1000
                        });
                    }
                });

            } else {
                //发异步把用户状态进行更改
                $.post('${backend_api_url `/channel/status`}$', {'id': id}, function (res) {
                    if (res.code === 0) {
                        $(obj).attr('title', '启用')
                        $(obj).find('i').html('&#xe601;');

                        $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-bg-gray').addClass('layui-bg-blue').html('已启用');
                        layer.msg('已启用!', {
                            icon: 6,
                            time: 1000
                        });
                    } else {
                        //操作失败
                        layer.msg(res.message, {
                            icon: 5,
                            time: 1000
                        });
                    }
                });
            }
        });
    }

    //自定义的render渲染输出多列表格
    var layout = [
        {
            name: '栏目名称',
            treeNodes: true,
            headerClass: 'value_col',
            colClass: 'value_col',
            style: 'width: 40%'
        },
        {
            name: '模型',
            headerClass: 'td-model',
            colClass: 'td-model',
            style: 'width: 10%',
            render: function (row) {
                return row.modelDesc;
            }
        },
        {
            name: '栏目类型',
            headerClass: 'td-type',
            colClass: 'td-type',
            style: 'width: 10%',
            render: function (row) {
                return row.typeDesc;
            }
        },
        {
            name: '状态',
            headerClass: 'td-status',
            colClass: 'td-status',
            style: 'width: 10%',
            render: function (row) {
                //启用禁用状态值
                //console.log('----'+row.state);
                if (row.status === 1) {
                    return '<span class="layui-badge layui-bg-blue">已启用</span>';
                }
                return '<span class="layui-badge layui-bg-blue  layui-bg-gray">已停用</span>';
            }
        },
        {
            name: '操作',
            headerClass: 'td-manage',
            colClass: 'td-manage',
            style: 'width: 20%',
            render: function (row) {
                if (row.status === 1) {
                    return '<a onclick="member_stop(this,' + row.id + ')" href="javascript:;" title="启用"><i class="layui-icon">&#xe601;</i></a>' +
                        '<a title="添加子类" onclick="WeAdminEdit(\'添加\',\'${backend_url `/channel/add`}$?id=' + row.id + '\')" href="javascript:;"><i class="layui-icon">&#xe654;</i></a>' +
                        '<a title="编辑" onclick="WeAdminEdit(\'编辑\',\'${backend_url `/channel/edit`}$?id=' + row.id + '\')" href="javascript:;"><i class="layui-icon">&#xe642;</i></a>' +
                        '<a title="管理内容" onclick="ShowContent(' + row.id + ')"><i class="layui-icon">&#xe629;</i></a>' +
                        '<a title="删除" onclick="del(' + row.id + ')" href="javascript:;">\<i class="layui-icon">&#xe640;</i></a>';
                }
                return '<a onclick="member_stop(this,' + row.id + ')" href="javascript:;" title="停用"><i class="layui-icon">&#xe62f;</i></a>' +
                    '<a title="添加子类" onclick="WeAdminEdit(\'添加\',\'${backend_url `/channel/add`}$?id=' + row.id + '\')" href="javascript:;"><i class="layui-icon">&#xe654;</i></a>' +
                    '<a title="编辑" onclick="WeAdminEdit(\'编辑\',\'${backend_url `/channel/edit`}$?id=' + row.id + '\')" href="javascript:;"><i class="layui-icon">&#xe642;</i></a>' +
                    '<a title="管理内容" onclick="ShowContent(' + row.id + ')"><i class="layui-icon">&#xe629;</i></a>' +
                    '<a title="删除" onclick="del(' + row.id + ')" href="javascript:;">\<i class="layui-icon">&#xe640;</i></a>';
            }
        },
    ];
    //加载扩展模块 treeGird
    //		layui.config({
    //			  base: './static/js/'
    //			  ,version: '101100'
    //			}).use('admin');
    layui.extend({
        admin: '{/}../../resource/backend/js/admin',
        treeGird: '{/}../../resource/backend/lib/layui/lay/treeGird' // {/}的意思即代表采用自有路径，即不跟随 base 路径
    });
    layui.use(['treeGird', 'jquery', 'admin', 'layer'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            admin = layui.admin,
            treeGird = layui.treeGird;

        $.post('${backend_api_url `/channel/index`}$', function (res) {
            var tree1 = layui.treeGird({
                elem: '#demo', //传入元素选择器
                spreadable: true, //设置是否全展开，默认不展开
                nodes: res.data,
                /*
                 nodes: [{
                 "id": "1",
                 "name": "父节点1",
                 "children": [{
                 "id": "11",
                 "name": "子节点11"
                 },
                 {
                 "id": "12",
                 "name": "子节点12"
                 }
                 ]
                 },
                 {
                 "id": "2",
                 "name": "父节点2",
                 "children": [{
                 "id": "21",
                 "name": "子节点21",
                 "children": [{
                 "id": "211",
                 "name": "子节点211"
                 }]
                 }]
                 }
                 ],
                 */
                layout: layout
            });

            $('#collapse').on('click', function () {
                layui.collapse(tree1);
            });

            $('#expand').on('click', function () {
                layui.expand(tree1);
            });
        }, 'json');

        //点击栏目名称
        $('body').on('click', 'cite', function () {
            //获取栏目id
            var cateId = $(this).parents('tr').attr('id');
            var title = $(this).text()
            var type = $(this).parents('tr').data('type')
            //console.log(cateId);
            //self.location.href = '../article/index.html?catid='+cateId;
            //WeAdminEdit(title,'../article/index.html?catid='+cateId);
            var index = layer.open({
                type: 2,
                content: '${backend_url `/channel_model/index`}$' + '?type=' + type + '&channel_id=' + cateId + '&with_tab=false',
                title: '栏目 ' + cateId + ' 数据',
                area: ['90%', '90%'],
                maxmin: true
            });
            layer.full(index);

            var url = $(this).children('a').attr('_href');
            var title = $(this).find('cite').html();
            var index = $('.left-nav #nav li').index($(this));

            for (var i = 0; i < $('.x-iframe').length; i++) {
                if ($('.x-iframe').eq(i).attr('tab-id') == index + 1) {
                    tab.tabChange(index + 1);
                    event.stopPropagation();
                    return;
                }
            }

            tab.tabAdd(title, url, index + 1);
            tab.tabChange(index + 1);


        });

    });

    //删除栏目
    function del(Id) {
        var $ = layui.$;
        layer.confirm('确定要删除栏目？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            delpost();
        });

        function delpost() {
            $.post('${ backend_api_url `/channel/delete` }$', {'id': Id}, function (res) {
                if (res.code === 0) {
                    layer.msg(res.message, {
                        icon: 6,
                        time: 1000
                    });
                    //删除元素节点
                    $('#id_' + Id).parents('tr').remove();
                    //刷新栏目数量
                    reloadCatcount();
                } else {
                    layer.msg(res.message, {
                        icon: 5,
                        time: 2000
                    });
                }
            });
        }
    }

    // 展示栏目内容
    function ShowContent(id) {
        var $ = layui.$;
        $('#id_' + id).parents('cite').trigger('click');
    }
</script>
</html>
